Skip to content

Run: show every check before the first image read, and make the header check linear (v0.9.0 release blocker) - #567

Merged
guijacquemet merged 5 commits into
mainfrom
claude/fix-run-hang
Nov 26, 2026
Merged

guijacquemet merged 5 commits into
mainfrom
claude/fix-run-hang

Conversation

@guijacquemet

@guijacquemet guijacquemet commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Head: 7aa55ee (origin/main 88a1c42 merged in). The review of f0986a3 is out of date.

What the owner saw (Colab, v0.9.0 release commit B ca3b3c6 / A 62b2790)

The owner pressed Run on about 200 images on Google Drive, with mixed channel layouts and a fresh output folder. The notebook showed "Preparing: checking the folders and the image headers again · 0:00 elapsed" and nothing changed for 10–15 minutes. The run then finished. Re-running the cell during that time just waited.

Root cause

This is not a deadlock, and it is not new in v0.9.0: ad8abad behaves the same (12,000 images: 24.2 s there against 27.4 s at A, on local disk).

  1. No progress before the first read. The run's checks before the first image (run/pipeline.py _locked_run → preflight(bind_headers=True), run_checks/check_planes, then compute_rows → source_content.with_content) report nothing.
  2. The timer did not move. Wait redraws, elapsed time included, only when progress is reported, and the run executes synchronously in the button callback.
  3. What takes the time on Drive is the content SHA-256. In a verify_content run (the notebook's default, and any fresh output folder, Content hashing of sources is off by default #159), the run reads every image whole for its SHA-256 before the first pixel. The header check itself reads only headers. See the measurements below.
  4. Two O(n²) steps in the check. run/resume.py _staging_key computed MetadataReport.dtype, a pass over every header, once per image. mask_names._mask_owner compared each image name with every other one. These matter for large experiments, not for 200 images.
  5. Re-running the cell waited because the kernel was busy inside the callback. It was not the run lock, which is released in a finally.

Bytes read and opens per image (784 MB of TIFFs, notebook-default run, fresh output folder)

Measured with /proc/self/io rchar at phase boundaries and strace for opens:

Phase Opens / image Bytes read
Header check (preflight, bind_headers) 1 open, ~4 stats headers only (0.00× data)
Projection marker + check_planes 2 headers only
Content SHA-256 (with_content) 1 1.00× data
First image read
Pixel read + SHA-256 after the read 2 2.00× data
SHA-256 at publish (content_changed) 1 1.00× data

On Drive, the time before the first read is about one whole read per image plus 4 opens. At 200 images, 3–4.5 s per image fits files of roughly 100–300 MB. Check (step 1) never hashes content, so nothing is hashed twice between Check and Run. Within one Run, each image is read whole 4 times.

I did not simulate slow storage: there is no FUSE in this container, and a Python-level read throttle undercounts tifffile's reads. The estimate above is a model from the measured counts.

Fix

  • RunMode(checking=...) passes progress out of the run. It is called with preflight's (phase, done, total, path), then with the phase contents (run.phases.CONTENTS) once per image hashed. It is operational only, like workers. run_experiment keeps its 14 parameters. compute_rows takes a Reporting(reading, checking) and keeps its 8 parameters.
  • What the notebook shows: each phase with real counts, for example "Preparing: reading the image headers again · 120 of 200" and "Preparing: reading each image whole for its content SHA-256 · 12 of 200", ending at "N of N". The start/end placeholders that preflight sends (such as ("masks", 0, 1, "") with no masks) no longer show "0 of 1". Wait.ticking() redraws the elapsed time every second from a thread. The label, clocks and line change together under one lock, and the thread is joined before the result replaces the line.
  • While the run goes, a note says that a cell run meanwhile waits for it, and how to interrupt it (Colab: Runtime > Interrupt execution).
  • Both O(n²) steps are now linear. The pixel type is taken once per run. _mask_owner looks up the prefixes of the name; a test checks it against the old rule on 400 random names, including top-level images.
  • Not changed: what is read and verified.

Benchmarks (local disk)

Header check, time to the first read callback (2 conditions × 4 repeats × 3 units, 3- and 2-channel repeats):

images main this branch
4,800 7.40 s 4.62 s
12,000 27.4–30.0 s 10.3 s
24,000 72–75 s 24–27 s

Identical outputs:

  • 4,800 images, main vs f0986a3: plane_histograms.csv, experiment_design.csv and image_qc.csv byte-identical (sha256 prefixes 1da6b3d989aa0dfe, 78503fbfa325f65d, dc6edcdac4c3b598).
  • 784 MB set, main 88a1c42 vs d9bf371 (before the review fixes in 7aa55ee): the same three files byte-identical (bd7914d2f396e5f4, a7a786acae4651d0, 3a412ac41cdec812).

Reductions that need the owner (not implemented: each one changes what is verified, or the reader)

  1. Drop the SHA-256 taken after each read, keeping the one at publish. Saves 1× data. A change after a read that is undone before publish would no longer be caught; the fingerprint after the read stays.
  2. Turn verify_content off by default on a fresh output folder or on Drive. Saves 3× data. Reuse would go by size + mtime_ns only, so a rewrite of the same size with its time set back would not be seen.
  3. Hash in the same pass as the pixel read. Saves 1× data with no loss of checking, but it changes the reader.
  4. Reuse the header check's parse for the projection marker and check_planes. Saves 2 opens per image, headers only, bound to the same fingerprint. This is engineering-only, not trivial, and left for later.

Tests

tests/test_run_checking_progress.py (12 tests) covers:

  • each header and each content SHA-256 reported before any read, with the outputs the same whether or not progress is reported;
  • the pixel type taken fewer times than there are images;
  • _mask_owner looks names up instead of scanning every image, and matches the old rule;
  • the ticking Wait redraws its elapsed time, stops with its block and does not overwrite the result;
  • the run wait's real totals, "N of N" at the end, and no "0 of 1" without masks;
  • the notebook Run's lines and its busy note.

Most of these fail on main. test_brick_api_surface is updated for the new RunMode field.

Checks on 7aa55ee

🤖 Generated with Claude Code

https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a

On a large mixed-layout experiment in Colab, Run showed "Preparing:
checking the folders and the image headers again 0:00 elapsed" for
10-15 minutes. The run checks the folder and every image header again
before its first image (preflight with bind_headers), with no progress
reported, and the notebook's Wait redraws its elapsed time only on a
progress report. Not a deadlock and not new in v0.9.0: the same at
ad8abad.

- RunMode(checking=...) passes preflight's (phase, done, total, path)
  progress through the run (operational only, like workers; the
  parameters of run_experiment are unchanged).
- The notebook shows each phase and each header of how many, and
  Wait.ticking() redraws the elapsed time every second in a thread while
  the run works, stopped before the result replaces the line. While the
  run goes, a note says a cell run meanwhile waits for it.
- Two O(n^2) steps of the check: each staging key took
  MetadataReport.dtype (a pass over every header), and the mask-name
  screen compared each image name with every other one.

Outputs byte-identical on a 4,800-image tree; the check before the first
image went from 30.0 s to 10.3 s (12,000 images) and 72-75 s to 24-27 s
(24,000 images) on local disk.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a
…move

PREPARING and BUSY_NOTE live with the Wait they label, in
notebook_progress.py; the full check had failed only on the line count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a
CHANGELOG.md: both Unreleased entries kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a
… first image

The owner's run (about 200 images on Google Drive) spent 10-15 minutes
before the first read. Measured on 784 MB of TIFFs: before the first
read, a verify_content run (the notebook's default, and any fresh output
folder) reads every image whole once (1.00x the data) for its content
SHA-256, in source_content.with_content, with no progress. The header
check reads only headers (0.00x). Each image is opened 4 times before
the first read (header, projection marker, check_planes, SHA-256).

with_content now reports each image hashed; the run passes it to
RunMode.checking as the phase "contents" (run.phases.CONTENTS), and the
notebook shows "Preparing: reading each image whole for its content
SHA-256 · n of N". compute_rows takes a Reporting (reading, checking)
instead of the progress callable, keeping its 8 parameters. What is read
and verified is unchanged; outputs are byte-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a

Copy link
Copy Markdown
Contributor Author

New head: d9bf371. The review on f0986a3 is out of date. New since then:

Where the owner's 10–15 minutes go (about 200 images, Google Drive)

Method. 6 uncompressed TIFFs, 98–147 MB each (784 MB total), with mixed layouts. I ran the notebook's default run (verify_content on, fresh output folder). Bytes were measured with /proc/self/io rchar at each phase boundary, and file opens with strace, per image:

Phase Opens / image Bytes read Local time
Folder + header check (preflight, bind_headers) 1 open, ~4 stats headers only (0.00× data) 0.02 s
Projection marker + check_planes 2 headers only —
Content SHA-256 (source_content.with_content) 1 1.00× data (every image read whole) 0.94 s
First image read
Pixel read + SHA-256 after the read 2 2.00× data 10.7 s
SHA-256 again at publish (content_changed) 1 1.00× data 0.8 s

Cause. Before the first read, the only whole-file read is the content SHA-256 that verify_content takes. verify_content is the notebook's default, and it is also on for any fresh output folder (#159). At 200 images taking 3–4.5 s each, one whole read per image fits files of roughly 100–300 MB at the Drive throughput Colab usually gets (tens of MB/s), plus 4 opens per image. The header check itself reads only headers. Check (step 1) never hashes content, so nothing is hashed twice between Check and Run. Within one Run, though, each image is read whole 4 times: SHA-256 before, the pixels, SHA-256 after, and SHA-256 at publish. The reading phase on Drive therefore costs about 3× the "Preparing" phase.

What d9bf371 changes. The hashing pass is reported as the phase contents: "Preparing: reading each image whole for its content SHA-256 · n of N", with the elapsed time ticking. Nothing about what is read or verified changes. The outputs are byte-identical to main 88a1c42 on that set (sha256 prefixes: plane_histograms.csv bd7914d2f396e5f4, experiment_design.csv a7a786acae4651d0, image_qc.csv 3a412ac41cdec812).

Reductions that change what is verified (owner decisions, not implemented)

  1. Drop the SHA-256 after the read, keeping the one at publish. Saves 1× data. What would no longer be caught: a change that happens after an image's read and is undone before publish. The fingerprint after the read is still checked.
  2. Turn verify_content off by default on a fresh output folder or on Drive. Saves 3× data. Reuse would then go by fingerprint alone (size + mtime_ns). A rewrite of the same size with its time set back would not be seen.
  3. Take the SHA-256 in the same pass as the pixel read when a whole image is read. Saves 1× data with no loss of checking, but it changes the reader (decoding from the hashed bytes). That is a bigger change than this PR.
  4. Reuse the header check's parse for the projection marker and check_planes. Saves 2 opens per image, which costs latency on Drive. It reads only headers, bound to the same fingerprint, so it is engineering-only, but not trivial.

🤖 Generated with Claude Code


Generated by Claude Code

…lock

Review of f0986a3 (low findings):
- preflight's placeholders ("masks", 0, 1, "") made a run without masks
  show "0 of 1": a phase now starts counted only from the headers' start
  or a call with a path, and an end without a path is drawn only when the
  phase counted that total;
- the headers (and the content SHA-256 pass) now end at "N of N";
- Wait.start/phase set the label and clocks under the drawing lock, so
  the ticking thread never draws a new label with the old numbers;
- the test's copy of the old _mask_owner rule takes the folder with
  PurePosixPath, as the code did, and the random names include
  top-level images.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a
@guijacquemet guijacquemet changed the title Run: show the run's own header check, and make it linear (v0.9.0 release blocker) Run: show every check before the first image read, and make the header check linear (v0.9.0 release blocker) Nov 26, 2026
@guijacquemet
guijacquemet marked this pull request as ready for review November 26, 2026 01:35
@guijacquemet
guijacquemet merged commit 316be56 into main Nov 26, 2026
3 checks passed
@guijacquemet
guijacquemet deleted the claude/fix-run-hang branch November 26, 2026 01:35
guijacquemet pushed a commit that referenced this pull request Nov 26, 2026
One conflict, in CHANGELOG.md: both sides added entries at the top of the v0.9.0 list (the
#543 and #544 entries here; the #567 and #566 entries on main). Both kept. The notebooks'
RELEASE_REF, the RELEASE_CALLS entry and the pin assertion are put back to their pre-pin
values (the branch carried commit B's pins) so that commit B moves them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a
guijacquemet pushed a commit that referenced this pull request Nov 26, 2026
The full python tools/check.py on the tree of the merge commit 86d7674 (main at 316be56 with
#566 and #567 on top of the earlier v0.9.0 PRs): Ruff clean, 761 files formatted, pytest 8832
passed and 12 skipped, code rules passed; the Spec modules 2122 passed, 0 skipped; the notebook
pin and version tests 49 passed. Docs only: this commit is the v0.9.0 preparation commit A that
commit B pins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a
@guijacquemet guijacquemet mentioned this pull request Nov 26, 2026
3 of 9 tasks
guijacquemet added a commit that referenced this pull request Nov 26, 2026
Run progress: masks counter reaches N of N; stray docstring (follow-up of #567)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants